import { Component, OnInit,Input } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { Location }                 from '@angular/common';
import {Hero} from "../class/hero";
import {HeroService} from "../service/hero.service.service";
//import 'rxjs/add/operator/switchMap';
@Component({
  selector: 'app-hero-detail',
  templateUrl: './hero-detail.component.html',
  styleUrls: ['./hero-detail.component.css'],
  providers:[HeroService]
})
export class HeroDetailComponent implements OnInit {
  //@Input() hero:Hero;
  hero:Hero;
  constructor(
    private heroService:HeroService,
    private route:ActivatedRoute,
    private location:Location
  ) { }

  ngOnInit() {
    this.route.params.subscribe((params)=>{
      this.heroService.getHero(Number(params['id'])).then(data=>{
        this.hero = data;
      });
    });
   /* this.route.paramMap
      .switchMap((params: ParamMap) => this.heroService.getHero(+params.get('id')))
      .subscribe(hero => this.hero = hero);*/
  }

}
